package com.cms.web.afterSaleService;

import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import net.sf.json.JSONObject;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

import com.biz.FlowManagerServiceMgr;
import com.cms.persistence.contractManager.accreditationContract.PSHTMX;
import com.cms.pub.OneBarcodeUtil;
import com.common.util.DateUtil;
import com.dal.common.sequence.UUIDGenerator;
import com.metadata.biz.MetaDataServiceMgr;
import com.metadata.bizmodel.SYS_MODEL;
import com.persistence.FLOW_TASK_LIST;
import com.persistence.qxgl.beans.SYSUser;
import com.pub.util.EMPJsonUtil;
import com.pub.util.FileUtil;
import com.web.BaseController;
import com.efounder.builder.base.data.EFDataSet;
import com.efounder.builder.base.data.EFRowSet;
import com.efounder.builder.meta.bizmodel.SYS_MDL_CTN;
import com.efounder.dict.DMTServiceMgr;
import com.efounder.dict.FCTServiceMgr;
import com.efounder.eai.data.JParamObject;
import com.efounder.form.EFFormDataModel;
import com.efounder.form.server.provider.FormModelDataProvider;
import com.efounder.form.server.resolver.util.FormModelDataResolverUtil;

/** 
 * 评审合同控制器
 * 
 * @author ES
 * @version 1.0
 */
@Controller
@RequestMapping(value="/cmsAfterSaleNoticeServiceManager")
public class EMPAfterSaleNoticeServiceController extends BaseController{
	@Autowired
	private                            DMTServiceMgr                                   DMTService;
	
	@Autowired
	private                            FCTServiceMgr                                   FCTService;
	
	@Autowired
	private                       MetaDataServiceMgr                           metaDataServiceMgr;
	
	@Autowired
	private                    FlowManagerServiceMgr                           FlowManagerService;

	@Autowired
	private                FormModelDataResolverUtil                            formModelResolver;
		
	@Autowired
	private                    FormModelDataProvider                                formModelUtil;
	
	@Autowired
	public                               HttpSession                                      session;
	
	/**
	 * 生产申请单
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/afterSaleServiceNotice")
	public String afterSaleServiceNotice(@RequestParam String F_YEAR, String F_MONTH, Model model) throws Exception {	
		EFDataSet       ndDataset = EFDataSet.getInstance();
		EFRowSet         ndRowset = EFRowSet.getInstance();
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		
		for(int i = 1; i <= 12; i++) {
			if(i < 10) {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + "0" + i);
				ndRowset.putString("F_NDMC", F_YEAR + "0" + i);
				ndDataset.insertRowSet(ndRowset);
			} else {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + i);
				ndRowset.putString("F_NDMC", F_YEAR + i);
				ndDataset.insertRowSet(ndRowset);
			}
		}
		model.addAttribute("ndDataset", ndDataset);
		model.addAttribute("F_KJQJ", F_YEAR + F_MONTH);
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName("BILL_WHERE", " F_KJQJ = '" + F_YEAR + F_MONTH + "' and F_CODE = '" + user.getUSER_ORGID() + "' and F_DJZT = '1'");
		PO.SetValueByParamName("BILL_ORDER", " desc");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormEnumProvider");
		EFFormDataModel formDataModel = formModelUtil.loadForm(PO);
		model.addAttribute("dataset", formDataModel.getBillDataSet());
		model.addAttribute("F_DJZT", "1");
		return "/cms/afterSaleServiceNotice/list";
	}
	
	/**
	 * 生产申请单
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/afterSaleServiceNoticeApproval")
	public String afterSaleServiceNoticeApproval(@RequestParam String F_YEAR, String F_MONTH, Model model) throws Exception {	
		EFDataSet       ndDataset = EFDataSet.getInstance();
		EFDataSet      flowNodeDS = null;
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = "";
		
		ndDataset = getKJQJDataSet(F_YEAR);
		flowNodeDS = getFlowNodeDataSet(user);
		
		model.addAttribute("ndDataset", ndDataset);
		model.addAttribute("flowNodeDS", flowNodeDS);
		model.addAttribute("F_KJQJ", F_YEAR + F_MONTH);
		
		if(flowNodeDS.getRowCount() > 0) {
			model.addAttribute("FLOW_NODE", flowNodeDS.getRowSet(0).getString("NODE_ID", ""));
			BILL_WHERE = " and BIZ_DATE = '" + F_YEAR + F_MONTH + "' and ((NODE_TAG = '" + flowNodeDS.getRowSet(0).getString("NODE_ID", "") + "' and RESR_STATUS = 'pending') or "
			           + "(NODE_SRC = '" + flowNodeDS.getRowSet(0).getString("NODE_ID", "") + "' and RESR_STATUS = 'pending' and RESR_IN_CAUSE != 'rollback')) ";
			
			PO.SetValueByParamName("TABLE_NAME", "FLOW_TASK_LIST");
			PO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
			PO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
			PO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
			PO.SetValueByParamName("TASK_TO_UNIT", user.getUSER_ORGID());
			PO.SetValueByParamName("TASK_TO_USER", user.getUSER_ID());
			PO.SetValueByParamName("BILL_ORDER", " FLOW_TASK_LIST.NODE_TAG, FLOW_TASK_LIST.BIZ_DJBH desc");
			PO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
			
			flowNodeDS = FlowManagerService.loadFlow1(PO);			
			model.addAttribute("dataset", flowNodeDS);
		}
		return "/cms/afterSaleServiceNotice/approvalList";
	}
	
	/**
	 * 生产申请单
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/afterSaleServiceNoticeApproval/list")
	public String afterSaleServiceNoticeApprovalList(@RequestParam String F_KJQJ, @RequestParam String FLOW_NODE, Model model) throws Exception {	
		EFDataSet       ndDataset = EFDataSet.getInstance();
		EFDataSet      flowNodeDS = null;
		JParamObject           PO = JParamObject.Create();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = "";
		EFDataSet          flowDS = null;
		
		ndDataset = getKJQJDataSet(F_KJQJ.substring(0, 4));
		flowNodeDS = getFlowNodeDataSet(user);
		
		BILL_WHERE = " and BIZ_DATE = '" + F_KJQJ + "' and ((NODE_TAG = '" + FLOW_NODE + "' and RESR_STATUS = 'pending') or "
		           + "(NODE_SRC = '" + FLOW_NODE + "' and RESR_STATUS = 'pending' and RESR_IN_CAUSE != 'rollback')) ";
		
		PO.SetValueByParamName("TABLE_NAME", "FLOW_TASK_LIST");
		PO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		PO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		PO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		PO.SetValueByParamName("TASK_TO_UNIT", user.getUSER_ORGID());
		PO.SetValueByParamName("TASK_TO_USER", user.getUSER_ID());
		PO.SetValueByParamName("BILL_ORDER", " FLOW_TASK_LIST.NODE_TAG, FLOW_TASK_LIST.BIZ_DJBH desc");
		PO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
		
		flowDS = FlowManagerService.loadFlow1(PO);			
		model.addAttribute("dataset", flowDS);
		model.addAttribute("FLOW_NODE", FLOW_NODE);
		model.addAttribute("ndDataset", ndDataset);
		model.addAttribute("flowNodeDS", flowNodeDS);
		model.addAttribute("F_KJQJ", F_KJQJ);
		return "/cms/afterSaleServiceNotice/approvalList";
	}
	
	/**
	 * 生产申请单
	 * @param model
	 * @return
	 * @throws Exception 
	 */
	@RequestMapping("/afterSaleServiceNotice/list")
	public String accreditationContractList(@RequestParam String F_KJQJ, @RequestParam String F_DJZT, Model model) throws Exception {	
		EFDataSet       ndDataset = EFDataSet.getInstance();
		EFRowSet         ndRowset = EFRowSet.getInstance();
		JParamObject           PO = JParamObject.Create();
		String             F_YEAR = F_KJQJ.substring(0, 4);
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = " F_KJQJ = '" + F_KJQJ + "' and F_CODE = '" + user.getUSER_ORGID() + "'";
		
		if(!F_DJZT.equals("-1")) {
			BILL_WHERE += " and F_DJZT = '" + F_DJZT + "'";
		}
		
		for(int i = 1; i <= 12; i++) {
			if(i < 10) {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + "0" + i);
				ndRowset.putString("F_NDMC", F_YEAR + "0" + i);
				ndDataset.insertRowSet(ndRowset);
			} else {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + i);
				ndRowset.putString("F_NDMC", F_YEAR + i);
				ndDataset.insertRowSet(ndRowset);
			}
		}
		model.addAttribute("ndDataset", ndDataset);
		model.addAttribute("F_KJQJ", F_KJQJ);
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
		PO.SetValueByParamName("BILL_ORDER", " desc");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormEnumProvider");
		EFFormDataModel formDataModel = formModelUtil.loadForm(PO);
		model.addAttribute("dataset", formDataModel.getBillDataSet());
		model.addAttribute("F_DJZT", F_DJZT);
		return "/cms/afterSaleServiceNotice/list";
	}
	
	/**
	 * 生产申请单添加
	 * @param model
	 * @return
	 */
	@RequestMapping("/afterSaleServiceNotice/add")
	public String afterSaleServiceNoticeAdd(Model model) {	
		SYSUser                  user = (SYSUser) session.getAttribute("contextUser");
		String                 F_GUID = UUIDGenerator.nextId();
		EFRowSet               rowset = EFRowSet.getInstance();
		String                strDate = DateUtil.date3String(DateUtil.PATTERN_DATE);
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;

		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_TYPE", "start");
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		if(flowNodeDS != null && flowNodeDS.getRowCount() > 0) {
			rowset.putString("FLOW_NODE_NAME", flowNodeDS.getRowSet(0).getString("NODE_NAME", ""));
			model.addAttribute("nodeRowSet", flowNodeDS.getRowSet(0));
			model.addAttribute("canEdit", "1");
		} else {
			rowset.putString("FLOW_NODE_NAME", "提交任务");
			model.addAttribute("canEdit", "0");
			model.addAttribute("canSubmit", "0");
			model.addAttribute("canRetrieve", "0");
			model.addAttribute("canRollback", "0");
		}
		
		rowset.putString("F_KJQJ", DateUtil.date3String("yyyyMM"));
		rowset.putString("F_GUID", F_GUID);
		rowset.putString("F_CODE", user.getUSER_ORGID());
		rowset.putString("F_ZDR", user.getUSER_ID());
		rowset.putString("F_ZDRMC", user.getUSER_NAME());
		rowset.putString("F_ZDRQ", strDate);
		rowset.putString("F_CODE", user.getUSER_ORGID());
		rowset.putString("F_DJZT", "1");
		model.addAttribute("dictObject", rowset);
		return "/cms/afterSaleServiceNotice/form";
	}
	
	/**
	 * 评审合同添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/afterSaleServiceNotice/update", method=RequestMethod.POST)
	public  ModelAndView afterSaleServiceNoticeUpdate(@RequestBody Map dataMap, Model model) throws Exception {  
		EFRowSet              rowSet = null;
		EFDataSet        itemDataSet = null;
		EFRowSet          metaRowSet = EFRowSet.getInstance();
		EFRowSet              rowset = EFRowSet.getInstance();
		String              F_CHDATE = "";
		JParamObject              PO = JParamObject.Create();
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;
		SYSUser                 user = (SYSUser) session.getAttribute("contextUser");
		EFDataSet itemObjColsDataSet = metaDataServiceMgr.getSYS_OBJCOLS("SHFWTZMX");
		metaRowSet.setDataSet("SHFWTZMX", itemObjColsDataSet);
		
		//将json数据转化为EFDataSet
		rowSet = EMPJsonUtil.convertMapToRowSet(dataMap, metaRowSet);
		
		itemDataSet = rowSet.getDataSet("SHFWTZMX");

		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_ID", "N1");
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		

		if(flowNodeDS == null || flowNodeDS.getRowCount() <= 0) {
			return ajaxDoneError("提交失败！原因：<br>【" + user.getUSER_ID() + "-" + user.getUSER_NAME() + "】没有权限提交单据！");
		}

		itemDataSet.setTableName("SHFWTZMX");
		rowset.setDataMap(rowSet.getDataMap());
		rowset.remove("SHFWTZMX");
		rowset.setDataSet("SHFWTZMX", itemDataSet);
		rowset.putString(EFFormDataModel._FORMEDITSAVETYPE_, "" + EFFormDataModel._FORM_SAVE_ITEMS_ALL_);

		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "CMSSaveFormToFlow");
		PO.SetValueByParamName("BILL_WHERE", " F_GUID = '" + rowSet.getString("F_GUID", "") + "'");
		PO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NOTE, rowSet.getString("F_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE, "N1");
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_BMBH, user.getUSER_ORGID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER, user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_STATUS, "pending");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_IN_CAUSE, "create");
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "01", rowSet.getString("F_XMBH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "02", rowSet.getString("F_XMMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "03", rowSet.getString("F_XLMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "04", rowSet.getString("F_LXR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "05", rowSet.getString("F_LXDH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "06", rowSet.getString("F_GZRY", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "07", rowSet.getString("F_GZSJ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "08", rowSet.getString("F_ZDR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "09", rowSet.getString("F_ZDRMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "10", user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "11", user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "01", rowSet.getString("F_ZDRQ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "02", DateUtil.date3String("yyyy-MM-dd"));
		
		EFFormDataModel formDataModel = formModelResolver.saveForm("SHFWTZXX", rowset, PO);
		if(formDataModel.getFormSaveStatus() == EFFormDataModel._FORM_SAVE_FAIL_) {
			return ajaxDoneError("保存失败！原因：<br>" + formDataModel.getFormSaveMessage());
		}
		rowset = formDataModel.getBillDataSet().getRowSet(0);
		F_CHDATE = rowset.getObject("F_CHDATE", "").toString();
		model.addAttribute("F_CHDATE", F_CHDATE);
		model.addAttribute("F_DJBH", rowset.getObject("F_DJBH", ""));
		return ajaxDoneSuccess("单据保存成功！单据编号【" + rowset.getObject("F_DJBH", "") + "】"); 
	}
	
	/**
	 * 评审合同添加保存
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/afterSaleServiceNotice/submit", method=RequestMethod.POST)
	public  ModelAndView accreditationContractApprovalSubmit(@RequestBody Map dataMap, Model model) throws Exception {  
		EFRowSet              rowSet = EMPJsonUtil.convertMapToRowSet(dataMap);
		EFRowSet              rowset = EFRowSet.getInstance();
		String              F_CHDATE = "";
		JParamObject              PO = JParamObject.Create();
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;
		EFRowSet          nodeRowset = EFRowSet.getInstance();
		SYSUser                 user = (SYSUser) session.getAttribute("contextUser");
		EFFormDataModel    formModel;
		String               strNode = (String) dataMap.get("nodeRowSet");                            //将节点信息提取出来
		dataMap.remove("nodeRowSet");                                                                 //把数据集中的节点信息删除
		EFRowSet          nodeRowSet = EMPJsonUtil.convertJsonToRowSet(strNode);                      //将节点JSON转化为EFRowSet
		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_ID", nodeRowSet.getString("NODE_ID", ""));
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		nodeRowset = flowNodeDS.getRowSet(0);

		if(nodeRowset == null) {
			return ajaxDoneError("提交失败！原因：<br>【" + user.getUSER_ID() + "-" + user.getUSER_NAME() + "】没有权限提交单据！");
		}
		
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormProvider");
		PO.SetValueByParamName("BILL_WHERE", " ####.F_GUID = '" + rowSet.getString("F_GUID", "") + "'");
		formModel = formModelUtil.loadForm(PO);
		EFRowSet headRowset = formModel.getBillDataSet().getRowSet(0);
		headRowset.putString("F_CHDATE", rowSet.getString("F_CHDATE", ""));
		
		PO = JParamObject.Create();
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NOTE, rowSet.getString("OP_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "01", rowSet.getString("F_XMBH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "02", rowSet.getString("F_XMMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "03", rowSet.getString("F_XLMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "04", rowSet.getString("F_LXR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "05", rowSet.getString("F_LXDH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "06", rowSet.getString("F_GZRY", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "07", rowSet.getString("F_GZSJ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "08", rowSet.getString("F_ZDR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "09", rowSet.getString("F_ZDRMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "10", user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "11", user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "15", rowSet.getString("F_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "01", rowSet.getString("F_ZDRQ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "02", DateUtil.date3String("yyyy-MM-dd"));
		if(dataMap.get("F_WGRQ") != null && !dataMap.get("F_WGRQ").toString().equals("")) {
			PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "03", dataMap.get("F_WGRQ").toString());
		}	

		headRowset.putString(EFFormDataModel._FORMEDITSAVETYPE_, "" + EFFormDataModel._FORM_SAVE_ITEM_);
		
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "CMSSubmitFormToFlow");
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		
		PO.SetValueByParamName(FLOW_TASK_LIST._FLOW_ID, "SHFWTZ_FLOW");
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE_TYPE, nodeRowset.getString("NODE_TYPE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC_NAME, nodeRowset.getString("NODE_NAME", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_BMBH, user.getUSER_ORGID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER, user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_STATUS, "pending");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_IN_CAUSE, "submit");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_OUT_CAUSE, "submit");
		
		EFFormDataModel formDataModel = formModelResolver.saveForm("SHFWTZXX", headRowset, PO);
		if(formDataModel.getFormSaveStatus() == EFFormDataModel._FORM_SAVE_FAIL_) {
			return ajaxDoneError("单据提交失败！原因：<br>" + formDataModel.getFormSaveMessage());
		}
		rowset = formDataModel.getBillDataSet().getRowSet(0);
		F_CHDATE = rowset.getObject("F_CHDATE", "").toString();
		model.addAttribute("F_CHDATE", F_CHDATE);
		model.addAttribute("F_DJBH", rowset.getObject("F_DJBH", ""));
		model.addAttribute("OP_NODE_NEXT", PO.GetValueByParamName("OP_NODE_NEXT", ""));
		return ajaxDoneSuccess("单据提交成功！"); 
	}
	
	/**
	 * 生产申请单取回
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/afterSaleServiceNotice/retake", method=RequestMethod.POST)
	public  ModelAndView afterSaleServiceNoticeRetake(@RequestBody Map dataMap, Model model) throws Exception {  
		EFRowSet              rowSet = EMPJsonUtil.convertMapToRowSet(dataMap);
		EFRowSet              rowset = EFRowSet.getInstance();
		String              F_CHDATE = "";
		JParamObject              PO = JParamObject.Create();
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;
		EFRowSet          nodeRowset = EFRowSet.getInstance();
		SYSUser                 user = (SYSUser) session.getAttribute("contextUser");
		EFFormDataModel    formModel;
		String               strNode = (String) dataMap.get("nodeRowSet");                            //将节点信息提取出来
		dataMap.remove("nodeRowSet");                                                                 //把数据集中的节点信息删除
		EFRowSet          nodeRowSet = EMPJsonUtil.convertJsonToRowSet(strNode);                      //将节点JSON转化为EFRowSet
		
		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_ID", nodeRowSet.getString("NODE_ID", ""));
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		nodeRowset = flowNodeDS.getRowSet(0);

		if(nodeRowset == null) {
			return ajaxDoneError("提交失败！原因：<br>【" + user.getUSER_ID() + "-" + user.getUSER_NAME() + "】没有权限提交单据！");
		}
		
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormProvider");
		PO.SetValueByParamName("BILL_WHERE", " ####.F_GUID = '" + rowSet.getString("F_GUID", "") + "'");
		formModel = formModelUtil.loadForm(PO);
		EFRowSet headRowset = formModel.getBillDataSet().getRowSet(0);
		headRowset.putString("F_CHDATE", rowSet.getString("F_CHDATE", ""));
		
		PO = JParamObject.Create();
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NOTE, rowSet.getString("F_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "01", rowSet.getString("F_XMBH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "02", rowSet.getString("F_XMMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "03", rowSet.getString("F_XLMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "04", rowSet.getString("F_LXR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "05", rowSet.getString("F_LXDH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "06", rowSet.getString("F_GZRY", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "07", rowSet.getString("F_GZSJ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "08", rowSet.getString("F_ZDR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "09", rowSet.getString("F_ZDRMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "10", user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "11", user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "15", rowSet.getString("F_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "01", rowSet.getString("F_ZDRQ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "02", DateUtil.date3String("yyyy-MM-dd"));
		if(dataMap.get("F_WGRQ") != null && !dataMap.get("F_WGRQ").toString().equals("")) {
			PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "01", dataMap.get("F_WGRQ").toString());
		}	

		headRowset.putString(EFFormDataModel._FORMEDITSAVETYPE_, "" + EFFormDataModel._FORM_SAVE_ITEM_);
		
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "CMSSubmitFormToFlow");
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		
		PO.SetValueByParamName(FLOW_TASK_LIST._FLOW_ID, "SHFWTZ_FLOW");
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE_TYPE, nodeRowset.getString("NODE_TYPE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC_NAME, nodeRowset.getString("NODE_NAME", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_BMBH, user.getUSER_ORGID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER, user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_STATUS, "pending");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_IN_CAUSE, "retake");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_OUT_CAUSE, "retake");
		
		EFFormDataModel formDataModel = formModelResolver.saveForm("SHFWTZXX", headRowset, PO);
		if(formDataModel.getFormSaveStatus() == EFFormDataModel._FORM_SAVE_FAIL_) {
			return ajaxDoneError("单据提交失败！原因：<br>" + formDataModel.getFormSaveMessage());
		}
		rowset = formDataModel.getBillDataSet().getRowSet(0);
		F_CHDATE = rowset.getObject("F_CHDATE", "").toString();
		model.addAttribute("F_CHDATE", F_CHDATE);
		model.addAttribute("F_DJBH", rowset.getObject("F_DJBH", ""));
		return ajaxDoneSuccess("单据提交成功！"); 
	}
	
	/**
	 * 评审合同编辑
	 * @param model
	 * @return
	 */
	@RequestMapping("/afterSaleServiceNotice/edit/{F_GUID}")
	public String afterSaleServiceNoticeEdit(@PathVariable("F_GUID") String F_GUID, @RequestParam String FLOW_NODE, Model model) {
		JParamObject           PO = JParamObject.Create();
		JParamObject   flowNodePO = JParamObject.Create();
		JParamObject       flowPO = JParamObject.Create();
		EFFormDataModel formModel;
		EFDataSet      flowNodeDS = null;
		EFDataSet  nextFlowNodeDS = null;
		EFRowSet       nodeRowset = EFRowSet.getInstance();
		EFRowSet   nextFodeRowset = EFRowSet.getInstance();
		EFDataSet     flowDataSet = EFDataSet.getInstance();
		EFRowSet       flowRowset = null;
		EFRowSet   nextFlowRowset = EFRowSet.getInstance();
		SYSUser              user = (SYSUser) session.getAttribute("contextUser");
		String         BILL_WHERE = "";
		JSONObject     jsonObject = new JSONObject();
		JParamObject     searchPO = JParamObject.Create();
		
		//获取流程节点
		flowNodePO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowNodePO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowNodePO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowNodePO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowNodePO.SetValueByParamName("NODE_ID", FLOW_NODE);
		flowNodePO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowNodePO);
		
		
		try {
			//加载模型数据
			PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
			PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormProvider");
			PO.SetValueByParamName("BILL_WHERE", " ####.F_GUID = '" + F_GUID + "'");
			PO.SetValueByParamName(SYS_MDL_CTN._BIZ_CTN_TYPE_JIDS_ + "_SHFWTZMX_EXT_COLUMN", " F_CPBH.F_GGXH as F_GGXH, F_CPBH.F_JLDW as F_JLDW");
			formModel = formModelUtil.loadForm(PO);
			EFDataSet itemCTN = metaDataServiceMgr.getSYS_MDL_CTN("SHFWTZModel", SYS_MDL_CTN._BIZ_CTN_TYPE_JIDS_);
			EFRowSet rowset = formModel.getBillDataSet().getRowSet(0);
			EFDataSet dataset = rowset.getDataSet(itemCTN.getRowSet(0).getString("CTN_FCT1", ""));

			if(flowNodeDS != null && flowNodeDS.getRowCount() > 0) {
				nodeRowset = flowNodeDS.getRowSet(0);
				//如果不是结束节点，则查询下一个节点
				if(!nodeRowset.getString("NODE_TYPE", "").equals("end")) {
					//查询下一个节点
					searchPO.SetValueByParamName("tableName", "FLOW_NODE_LIST");
					searchPO.SetValueByParamName("sqlWhere", "FLOW_ID = 'SHFWTZ_FLOW' and NODE_ID = '" + nodeRowset.getString("NODE_NEXT", "") + "'");
					searchPO.SetValueByParamName("searchCol", "NODE_ID");
					nextFlowNodeDS = DMTService.searchDictRow(searchPO);
					if(nextFlowNodeDS != null && nextFlowNodeDS.getRowCount() > 0) {
						nextFodeRowset = nextFlowNodeDS.getRowSet(0);
						nodeRowset.putString("NODE_NEXT_TYPE", nextFodeRowset.getString("NODE_TYPE", ""));
					}
				}
				//查询上一个节点
				searchPO.SetValueByParamName("tableName", "FLOW_NODE_LIST");
				searchPO.SetValueByParamName("sqlWhere", "FLOW_ID = 'SHFWTZ_FLOW' and NODE_NEXT = '" + nodeRowset.getString("NODE_ID", "") + "'");
				searchPO.SetValueByParamName("searchCol", "NODE_ID");
				nextFlowNodeDS = DMTService.searchDictRow(searchPO);
				if(nextFlowNodeDS != null && nextFlowNodeDS.getRowCount() > 0) {
					nextFodeRowset = nextFlowNodeDS.getRowSet(0);
					nodeRowset.putString("NODE_PRE", nextFodeRowset.getString("NODE_ID", ""));
					nodeRowset.putString("NODE_PRE_TYPE", nextFodeRowset.getString("NODE_TYPE", ""));
				}
				
				flowNodeDS = FlowManagerService.loadFlowNode(flowNodePO);
				
				//获取流程是否在结束流程列表中
				//获取当前流程信息
				BILL_WHERE = " BIZ_DATE = '" + rowset.getString("F_KJQJ", "") + "' and BIZ_DJBH = '" + rowset.getString("F_DJBH", "") + "' and "
				           + " FLOW_ID = 'SHFWTZ_FLOW'";
				//判断是否为会签节点，决定是否加上部门条件
				if(nodeRowset.getString("NODE_TYPE", "").equals("countersign")) {
					BILL_WHERE += " and TASK_TO_UNIT = '" + user.getUSER_ORGID() + "'";
				}
				
				
				flowPO.SetValueByParamName("tableName", "FLOW_TASK_END_LIST");
				flowPO.SetValueByParamName("BILL_ORDER", " (OP_ID + 0) desc ");
				flowPO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
				flowDataSet = FCTService.getFCTRows(flowPO);
				//如果有数据，则表示流程已经结束
				if(flowDataSet.getRowCount() > 0) {
					flowRowset = flowDataSet.getRowSet(0);
					//modify by prayer 2014-11-03 因为编辑的时候打开有问题，留着也没用，清空掉了
					for(int i = 1; i < 10; i++) {
						flowRowset.putString("F_CHAR0" + i, "");
					}
					for(int i = 10; i <= 20; i++) {
						flowRowset.putString("F_CHAR" + i, "");
					}
					flowRowset.putString("OP_NOTE", "");
					model.addAttribute("endFlowObject", flowRowset);
				} 
				//说明流程没有结束
				else {
					model.addAttribute("endFlowObject", "");
					//获取当前流程信息
					BILL_WHERE = " BIZ_DATE = '" + rowset.getString("F_KJQJ", "") + "' and BIZ_DJBH = '" + rowset.getString("F_DJBH", "") + "' and "
					           + " FLOW_ID = 'SHFWTZ_FLOW' and NODE_TAG = '" + nodeRowset.getString("NODE_ID", "") + "'";
					//判断是否为会签节点，决定是否加上部门条件
					if(nodeRowset.getString("NODE_TYPE", "").equals("countersign")) {
						BILL_WHERE += " and TASK_TO_UNIT = '" + user.getUSER_ORGID() + "'";
					}
					
					
					flowPO.SetValueByParamName("tableName", "FLOW_TASK_LIST");
					flowPO.SetValueByParamName("BILL_ORDER", " (OP_ID + 0) desc ");
					flowPO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
					flowDataSet = FCTService.getFCTRows(flowPO);
					if(flowDataSet.getRowCount() > 0) {
						flowRowset = flowDataSet.getRowSet(0);
						//modify by prayer 2014-11-03 因为编辑的时候打开有问题，留着也没用，清空掉了
						for(int i = 1; i < 10; i++) {
							flowRowset.putString("F_CHAR0" + i, "");
						}
						for(int i = 10; i <= 20; i++) {
							flowRowset.putString("F_CHAR" + i, "");
						}
						flowRowset.putString("OP_NOTE", "");
						model.addAttribute("flowObject", flowRowset);
					}
					
					if(flowRowset != null) {
						//获取下一个流程信息
						BILL_WHERE = " BIZ_DATE = '" + rowset.getString("F_KJQJ", "") + "' and BIZ_DJBH = '" + rowset.getString("F_DJBH", "") + "' and "
						           + " FLOW_ID = 'SHFWTZ_FLOW' and POP_ID = '" + flowRowset.getString("OP_ID", "") + "'";
						flowPO.SetValueByParamName("tableName", "FLOW_TASK_LIST");
						flowPO.SetValueByParamName("BILL_ORDER", " (OP_ID + 0) desc ");
						flowPO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
						flowDataSet = FCTService.getFCTRows(flowPO);
						if(flowDataSet.getRowCount() > 0) {
							nextFlowRowset = flowDataSet.getRowSet(0);
						}		
					}	
					//如果流程结束
					if(flowRowset == null) {
						model.addAttribute("canSubmit", "0");
						model.addAttribute("canRetrieve", "0");
						model.addAttribute("canRollback", "0");
					}
					//如果当前流程状态为代办，则可以提交和编辑,如果是申请单生成的，就不能编辑
					else if(flowRowset.getString("RESR_STATUS", "").equals("pending")) {
						if(rowset.getString("SHFW_DJBH", "").equals("")) {
							model.addAttribute("canEdit", "1");
						} else {
							model.addAttribute("canEdit", "0");
						}
						model.addAttribute("canSubmit", "1");
						model.addAttribute("canRetrieve", "0");
						model.addAttribute("canRollback", "0");
					}
					//如果已经处理过，则判断下一个流程，下一个流程如果为代办，则可以取回，否则不能取回
					else {
						if(nextFlowRowset.getString("RESR_STATUS", "").equals("pending")) {
							model.addAttribute("canEdit", "0");
							model.addAttribute("canSubmit", "0");
							if(flowRowset.getString("NODE_TAG", "").compareTo(nextFlowRowset.getString("NODE_TAG", "")) > 0) {
								model.addAttribute("canRetrieve", "0");
							} else {
								model.addAttribute("canRetrieve", "1");
							}
							model.addAttribute("canRollback", "0");
						} else {
							model.addAttribute("canEdit", "0");
							model.addAttribute("canSubmit", "0");
							model.addAttribute("canRetrieve", "0");
							model.addAttribute("canRollback", "0");
						}					
					}
				}
				
				jsonObject.putAll(nodeRowset);
				model.addAttribute("nodeRowSet", nodeRowset);
				model.addAttribute("jsonNodeRowSet", jsonObject.toString());
			} else {
				model.addAttribute("canEdit", "0");
				model.addAttribute("canSubmit", "0");
				model.addAttribute("canRetrieve", "0");
				model.addAttribute("canRollback", "0");
			}
			rowset.putString("F_CODE", user.getUSER_ORGID());
			model.addAttribute("dictObject", rowset);
			model.addAttribute("F_BMBH", user.getUSER_ORGID());
			model.addAttribute("dataset", dataset);			
			model.addAttribute("flowNodeObject", nodeRowset);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/cms/afterSaleServiceNotice/form";
	}	
	
	/**
	 * 取回评审合同
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/afterSaleServiceNotice/rollback", method=RequestMethod.POST)
	public  ModelAndView accreditationContractApprovalRollback(@RequestBody Map dataMap, Model model) throws Exception {  
		EFRowSet              rowSet = EMPJsonUtil.convertMapToRowSet(dataMap);
		EFRowSet              rowset = EFRowSet.getInstance();
		String              F_CHDATE = "";
		JParamObject              PO = JParamObject.Create();
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;
		EFRowSet          nodeRowset = EFRowSet.getInstance();
		SYSUser                 user = (SYSUser) session.getAttribute("contextUser");
		EFFormDataModel    formModel;
		String               strNode = (String) dataMap.get("nodeRowSet");                            //将节点信息提取出来
		dataMap.remove("nodeRowSet");                                                                 //把数据集中的节点信息删除
		EFRowSet          nodeRowSet = EMPJsonUtil.convertJsonToRowSet(strNode);                      //将节点JSON转化为EFRowSet
		
		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_ID", nodeRowSet.getString("NODE_ID", ""));
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		nodeRowset = flowNodeDS.getRowSet(0);

		if(nodeRowset == null) {
			return ajaxDoneError("提交失败！原因：<br>【" + user.getUSER_ID() + "-" + user.getUSER_NAME() + "】没有权限提交单据！");
		}
		
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormProvider");
		PO.SetValueByParamName("BILL_WHERE", " ####.F_GUID = '" + rowSet.getString("F_GUID", "") + "'");
		formModel = formModelUtil.loadForm(PO);
		EFRowSet headRowset = formModel.getBillDataSet().getRowSet(0);
		headRowset.putString("F_CHDATE", rowSet.getString("F_CHDATE", ""));
		
		PO = JParamObject.Create();
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NOTE, rowSet.getString("OP_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "01", rowSet.getString("F_XMBH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "02", rowSet.getString("F_XMMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "03", rowSet.getString("F_XLMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "04", rowSet.getString("F_LXR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "05", rowSet.getString("F_LXDH", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "06", rowSet.getString("F_GZRY", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "07", rowSet.getString("F_GZSJ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "08", rowSet.getString("F_ZDR", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "09", rowSet.getString("F_ZDRMC", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "10", user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "11", user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._F_CHAR + "15", rowSet.getString("F_NOTE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "01", rowSet.getString("F_ZDRQ", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._F_DATE + "02", DateUtil.date3String("yyyy-MM-dd"));

		headRowset.putString(EFFormDataModel._FORMEDITSAVETYPE_, "" + EFFormDataModel._FORM_SAVE_ITEM_);
		
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "CMSSubmitFormToFlow");
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		
		PO.SetValueByParamName(FLOW_TASK_LIST._FLOW_ID, "SHFWTZ_FLOW");
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE_TYPE, nodeRowset.getString("NODE_TYPE", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC, nodeRowset.getString("NODE_ID", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._NODE_SRC_NAME, nodeRowset.getString("NODE_NAME", ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_BMBH, user.getUSER_ORGID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER, user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_STATUS, "pending");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_IN_CAUSE, "rollback");
		PO.SetValueByParamName(FLOW_TASK_LIST._RESR_OUT_CAUSE, "rollback");
		
		EFFormDataModel formDataModel = formModelResolver.saveForm("SHFWTZXX", headRowset, PO);
		if(formDataModel.getFormSaveStatus() == EFFormDataModel._FORM_SAVE_FAIL_) {
			return ajaxDoneError("单据提交失败！原因：<br>" + formDataModel.getFormSaveMessage());
		}
		rowset = formDataModel.getBillDataSet().getRowSet(0);
		F_CHDATE = rowset.getObject("F_CHDATE", "").toString();
		model.addAttribute("F_CHDATE", F_CHDATE);
		model.addAttribute("F_DJBH", rowset.getObject("F_DJBH", ""));
		return ajaxDoneSuccess("单据提交成功！"); 
	}
	
	/**
	 * 打印生产申请
	 * @param model
	 * @return
	 */
	@RequestMapping("/afterSaleServiceNotice/print/{F_GUID}")
	public String afterSaleServiceNoticePrint(@PathVariable("F_GUID") String F_GUID, HttpServletRequest request, Model model) {
		JParamObject           PO = JParamObject.Create();
		JParamObject       flowPO = JParamObject.Create();
		EFFormDataModel formModel;
		String      fileSeparator = System.getProperty("file.separator");
		String          strFolder = request.getRealPath("") + fileSeparator + "WEB-INF" + fileSeparator + "img" + fileSeparator + "CMS" + fileSeparator + "SHFWTZ";
		EFRowSet       flowRowSet = null;
		String        strFilePath = "";
		String          strBacode = "";
		String         BILL_WHERE = "";
		
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, "SHFWTZModel");
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "FormProvider");
		PO.SetValueByParamName("BILL_WHERE", " ####.F_GUID = '" + F_GUID + "'");
		PO.SetValueByParamName(SYS_MDL_CTN._BIZ_CTN_TYPE_JIDS_ + "_SHFWTZMX_EXT_COLUMN", " F_CPBH.F_GGXH as F_GGXH, F_CPBH.F_JLDW as F_JLDW");
		
		
		try {
			
			//判断目录是否存在，每天上传的申请单都放到对应的一个目录下
            FileUtil.createDirectorys(strFolder);
            
            strFilePath = strFolder + fileSeparator + F_GUID + ".png";
            
            
			formModel = formModelUtil.loadForm(PO);
			EFDataSet itemCTN = metaDataServiceMgr.getSYS_MDL_CTN("SHFWTZModel", SYS_MDL_CTN._BIZ_CTN_TYPE_JIDS_);
			EFRowSet rowset = formModel.getBillDataSet().getRowSet(0);
			EFDataSet dataset = rowset.getDataSet(itemCTN.getRowSet(0).getString("CTN_FCT1", ""));

			//获取流程信息
			BILL_WHERE = " BIZ_DATE = '" + rowset.getString("F_KJQJ", "") + "' and BIZ_DJBH = '" + rowset.getString("F_DJBH", "") + "' and "
			           + " FLOW_ID = 'SHFWTZ_FLOW' and NODE_SRC = 'N2' and NODE_TAG = 'N3' and RESR_IN_CAUSE = 'submit'";
			flowPO.SetValueByParamName("tableName", "FLOW_TASK_LIST");
			flowPO.SetValueByParamName("BILL_ORDER", " (OP_ID + 0) desc ");
			flowPO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
			flowRowSet = FCTService.getFCTRow(flowPO);
			
			if(flowRowSet == null) {
				flowPO.SetValueByParamName("tableName", "FLOW_TASK_END_LIST");
				flowPO.SetValueByParamName("BILL_ORDER", " (OP_ID + 0) desc ");
				flowPO.SetValueByParamName("BILL_WHERE", BILL_WHERE);
				flowRowSet = FCTService.getFCTRow(flowPO);
			}
			if(flowRowSet != null) {
				rowset.putString("F_JLSP", flowRowSet.getString("OP_USER", ""));
				rowset.putString("F_JLSPMC", flowRowSet.getString("OP_USER_NAME", ""));
			}

			if(!FileUtil.checkExists(strFilePath)) {
				strBacode = rowset.getString("F_KJQJ", "") + "+" + rowset.getString("F_DJBH", "");
            	OneBarcodeUtil.createBarcode(strBacode, F_GUID + ".png", strFolder);
            }
			
			model.addAttribute("dictObject", rowset);
			model.addAttribute("dataset", dataset);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return "/cms/afterSaleServiceNotice/printForm";
	}
	
	/**
	 * 评审合同删除
	 * @param model
	 * @return
	 */
	@RequestMapping(value="/afterSaleServiceNotice/invalidForm", method=RequestMethod.POST)
	public  ModelAndView invalidForm(@RequestBody Map dataMap, Model model) throws Exception {  
		EFRowSet              rowSet = EMPJsonUtil.convertMapToRowSet(dataMap);
		EFRowSet              rowset = EFRowSet.getInstance();
		String              F_CHDATE = "";
		JParamObject              PO = JParamObject.Create();		
		SYSUser                  user = (SYSUser) session.getAttribute("contextUser");
		JParamObject           flowPO = JParamObject.Create();
		EFDataSet          flowNodeDS = null;
		EFRowSet           nodeRowset = EFRowSet.getInstance();
		
		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", rowSet.getString(FLOW_TASK_LIST._FLOW_ID, ""));
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("NODE_TYPE", "start");
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		nodeRowset = flowNodeDS.getRowSet(0);
		
		if(nodeRowset == null) {
			return ajaxDoneError("提交失败！原因：<br>【" + user.getUSER_ID() + "-" + user.getUSER_NAME() + "】没有权限提交单据！");
		}
		
		rowset.setDataMap(rowSet.getDataMap());
		rowset.remove(PSHTMX.class.getName());
		rowset.putString("F_DJZT", "0");
		rowset.putString(EFFormDataModel._FORMEDITSAVETYPE_, "" + EFFormDataModel._FORM_SAVE_ITEMS_ALL_);
		
		PO.SetValueByParamName(SYS_MODEL.SERVICE_ID, "CMSInvalidForm");
		PO.SetValueByParamName(SYS_MODEL.MODEL_ID, rowSet.getString(SYS_MODEL.MODEL_ID, ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._FLOW_ID, rowSet.getString(FLOW_TASK_LIST._FLOW_ID, ""));
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_BMBH, user.getUSER_ORGID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER, user.getUSER_ID());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_USER_NAME, user.getUSER_NAME());
		PO.SetValueByParamName(FLOW_TASK_LIST._OP_NODE, nodeRowset.getString("NODE_ID", ""));
		
		EFDataSet itemCTN = metaDataServiceMgr.getSYS_MDL_CTN(rowSet.getString(SYS_MODEL.MODEL_ID, ""), SYS_MDL_CTN._BIZ_CTN_TYPE_JBDS_);
		
		EFFormDataModel formDataModel = formModelResolver.submitForm(itemCTN.getRowSet(0).getString("CTN_FCT1", ""), rowset, PO);
		if(formDataModel.getFormSaveStatus() == EFFormDataModel._FORM_SAVE_FAIL_) {
			return ajaxDoneError("提交失败！原因：<br>" + formDataModel.getFormSaveMessage());
		}
		rowset = formDataModel.getBillDataSet().getRowSet(0);
		F_CHDATE = rowset.getObject("F_CHDATE", "").toString();
		model.addAttribute("F_CHDATE", F_CHDATE);
		model.addAttribute("F_DJBH", rowset.getObject("F_DJBH", ""));
		return ajaxDoneSuccess("单据分录保存成功！单据编号【" + rowset.getObject("F_DJBH", "") + "】");
	}
	
	/**
	 * 获取会计期间
	 * @param F_YEAR
	 * @return
	 */
	private EFDataSet getKJQJDataSet(String F_YEAR) {
		EFDataSet       ndDataset = EFDataSet.getInstance();
		EFRowSet         ndRowset = EFRowSet.getInstance();
		JParamObject           PO = JParamObject.Create();
		
		for(int i = 1; i <= 12; i++) {
			if(i < 10) {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + "0" + i);
				ndRowset.putString("F_NDMC", F_YEAR + "0" + i);
				ndDataset.insertRowSet(ndRowset);
			} else {
				ndRowset = EFRowSet.getInstance();
				ndRowset.putString("F_NDBH", F_YEAR + i);
				ndRowset.putString("F_NDMC", F_YEAR + i);
				ndDataset.insertRowSet(ndRowset);
			}
		}
		return ndDataset;
	}
	
	/**
	 * 获取会计期间
	 * @param F_YEAR
	 * @return
	 */
	private EFDataSet getFlowNodeDataSet(SYSUser user) {
		JParamObject          flowPO = JParamObject.Create();
		EFDataSet         flowNodeDS = null;
		
		//获取流程节点
		flowPO.SetValueByParamName("TABLE_NAME", "FLOW_NODE_LIST");
		flowPO.SetValueByParamName("FLOW_ID", "SHFWTZ_FLOW");
		flowPO.SetValueByParamName("FLOW_BM", user.getUSER_ORGID());
		flowPO.SetValueByParamName("FLOW_USER", user.getUSER_ID());
		flowPO.SetValueByParamName("BILL_ORDER", " NODE_ID");
		
		flowNodeDS = FlowManagerService.loadFlowNode(flowPO);
		return flowNodeDS;
	}
}
